﻿using System;
using System.Diagnostics;
using System.ServiceModel;
using System.Threading;
using Universe.WCF.Behaviors;

[ServiceContract(SessionMode = SessionMode.NotAllowed)]
public interface IDeliveryDemo
{
    void MyMethod(string arg);
}

internal class DeliveryDemoService : IDeliveryDemo
{
    public void MyMethod(string arg)
    {
    }
}

internal static class DeliveryServerConfiguration
{
    public static void Init()
    {
        TransparentDeliveryConfiguration.Common.OnServer =
            delegate(string action, DeliveryDictionary data)
                {
                    if (data.Contains("User"))
                    {
                        string userName = data.Get<string>("User");
                        Debug.WriteLine("User name: " + userName);
                    }

                    string culture = data.Get<string>("Culture");
                    Debug.WriteLine(
                        "Culture: "
                        + (string.IsNullOrEmpty(culture) ? "undefined" : culture)
                        );
                };
    }
}

internal static class DeliveryClientConfiguration
{
    public static void Init()
    {
        TransparentDeliveryConfiguration.Common.OnClient =
            delegate(string action, DeliveryDictionary data)
                {
                    if (Thread.CurrentPrincipal.Identity.IsAuthenticated)
                        data.Set("User", Thread.CurrentPrincipal.Identity.Name);

                    data.Set("Culture", Thread.CurrentThread.CurrentUICulture.NativeName);
                };
    }
}


internal class DeliveryClient
{
    public void Do()
    {
        IDeliveryDemo client = GetDeliveryDemoProxy();
        client.MyMethod("Hello");
    }

    private IDeliveryDemo GetDeliveryDemoProxy()
    {
        // реализация метода не важна
        throw new NotImplementedException();
    }
}